package com.example.newproject_overseas.Screen.Level


import android.util.Log
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.Divider
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
import com.example.newproject_overseas.ViewModel.JobViewModel
import com.example.newproject_overseas.components.TopApp
import com.example.newproject_overseas.model.entity.ModelItem
import kotlinx.coroutines.runBlocking

@Composable
fun TwoLevel(navController: NavHostController, occ1Id:String?) {
    var jobViewModel:JobViewModel= viewModel()
    var addressModel: List<ModelItem>? = null

    //网络请求
    runBlocking{
        //获取地址信息
        occ1Id?.let {
            jobViewModel.addressReq2(navController, it)
        }
        // 同步请求，阻塞主线程，不推荐
        addressModel = jobViewModel.addressChilderModel?.toList()
    }

    Log.i( "TwoLevel: ",addressModel.toString())
    Column(
        modifier = Modifier
            .fillMaxSize()
            .background(color = Color(0XFFEFF0F3)),

        ) {

        TopApp(title = "Work information", navController = navController)
        if (addressModel != null) {
            LazyColumn(modifier = Modifier) {
                items(addressModel!!) { data ->
                    Divider()
                    Row(modifier = Modifier
                        .clickable {

                        }
                        .padding(top = 10.dp, bottom = 10.dp)
                        .fillMaxWidth(),
                        verticalAlignment = Alignment.CenterVertically,
                        horizontalArrangement = Arrangement.Center
                    ) {
                        Text(text = data.name)
                    }
                }
            }
        }

    }}



